namespace Architecture.CrossCutting.LoggingEntities
{
    using Models;
    using Architecture.CrossCutting.RepositoryPattern.Logging;
    using Architecture.CrossCutting.Web.Tracing.Model;
    using System;
    using System.Data.Entity;
    using System.Linq;
    using Tracing.Models;
    using Web.WCF;

    public class LoggingServiceContext : DbContext
    {
        // Your context has been configured to use a 'LoggingServiceContext' connection string from your application's 
        // configuration file (App.config or Web.config). By default, this connection string targets the 
        // 'Architecture.CrossCutting.LoggingEntities.LoggingServiceContext' database on your LocalDb instance. 
        // 
        // If you wish to target a different database and/or database provider, modify the 'LoggingServiceContext' 
        // connection string in the application configuration file.
        public LoggingServiceContext()
            : base("name=LoggingServiceContext")
        {
            this.Database.Log = s => System.Diagnostics.Debug.WriteLine(s);

            this.Configuration.AutoDetectChangesEnabled = false;
            this.Configuration.LazyLoadingEnabled = false;
            this.Configuration.ProxyCreationEnabled = false;

            Database.SetInitializer<LoggingServiceContext>(null);
            //Database.SetInitializer<LoggingServiceContext>(new DropCreateDatabaseIfModelChanges<LoggingServiceContext>());
        }

        // Add a DbSet for each entity type that you want to include in your model. For more information 
        // on configuring and using a Code First model, see http://go.microsoft.com/fwlink/?LinkId=390109.

        public virtual DbSet<Log> Logs { get; set; }
        public virtual DbSet<IISLog> IISLogs { get; set; }
        public virtual DbSet<EFLog> EFLogs { get; set; }
        public virtual DbSet<WebApiLog> WebApiLogs { get; set; }
        public virtual DbSet<ServiceDetail> Services { get; set; }

        public virtual DbSet<WcfClientLog> WcfClientLogs { get; set; }

        public virtual DbSet<WcfServiceLog> WcfServiceLog { get; set; }

        protected override void OnModelCreating(DbModelBuilder modelBuilder)
        {
            modelBuilder.Configurations.Add(new Mapping.IISLogMap());
            modelBuilder.Configurations.Add(new Mapping.LogMap());
            modelBuilder.Configurations.Add(new Mapping.EFLogMap());
            modelBuilder.Configurations.Add(new Mapping.WebApiLogMap());

            modelBuilder.Configurations.Add(new Mapping.ServiceDetailMap());

            modelBuilder.Configurations.Add(new Mapping.WcfClientLogMap());
            modelBuilder.Configurations.Add(new Mapping.WcfServiceLogMap());

            base.OnModelCreating(modelBuilder);
        }
    }
}